**************************************************************************************************************
**	Replication do-file for "Social Democracy and the Birth of Working-Class Representation in Europe"
**  Purpose: Produce Figures 1&2 (England and Wales)
*************************************************************************************************************

/* set the directory */

/****************************
**		Figure 1
*****************************/
use "Britain prewar.dta", clear

**		calculate the total number of MPs per year
foreach x of numlist 1832 1835 1837 1841 1847 1852 ///
					 1857 1859 1865 1868 1874 1880 ///
					 1885 1886 1892 1895 1900 1906 ///
					 1910 1911 1918 1922 1923 1924 ///
					 1929 1931 1935 {
egen total_mps_parl`x'=count(rush_id) if parl_year==`x'
}

**		calculate the total number of working-class MPs per year
foreach x of numlist 1832 1835 1837 1841 1847 1852 ///
					 1857 1859 1865 1868 1874 1880 ///
					 1885 1886 1892 1895 1900 1906 ///
					 1910 1911 1918 1922 1923 1924 ///
					 1929 1931 1935 {
foreach i of varlist mp_manual{
egen `i'_tparl`x'=total(`i') if parl_year==`x'
gen `i'_pct_parl`x'=(`i'_tparl`x'/total_mps_parl`x')*100
drop `i'_tparl`x'				 
	}
}

collapse (firstnm) mp_*_pct*
xpose, v clear

split _varname, parse("parl") /* extract the year */
drop _varname _varname1
rename _varname2 year
destring year, replace
rename v1 mp_manual_related

label var year "Year"

**  Add the Labour's seat share
gen labour_share=.
replace labour_share=1.3  if year==1900
replace labour_share=4.8  if year==1906
replace labour_share=7    if year==1910
replace labour_share=6.4  if year==1911
replace labour_share=20.8 if year==1918
replace labour_share=29.7 if year==1922
replace labour_share=30.7 if year==1923
replace labour_share=33.3 if year==1924
replace labour_share=37.1 if year==1929
replace labour_share=30.6 if year==1931
replace labour_share=38   if year==1935

sort year
twoway (area labour_share year, lc(gs12) fc(gs12)) ///
(connect mp_manual_related year, lc(gs5) m(i) lw(.7)),   ///
	   xlabel(1832 1835 1837 1841 1847 1852 ///
	       1857 1859 1865 1868 1874 1880 ///
		   1885 1886 1892 1895 1900 1906 ///
		   1910 1911 1918 1922 1924 ///
		   1929 1931 1935,  labsize(4.7) alt angle(90)) xsize(10) ytitle("Percent Workers", size(6)) ///
		   ylabel(0(10)40, labsize(5)) xtitle(, size(6)) title("England and Wales", size(7)) name(mps, replace) ///
		   graphregion(color(white))   legend (order(1 "Labour Seat Share" 2 "Worker") row(1)) 

/********************************************
     Figure 2: Percentages for the Tree Map
*********************************************/
use "Britain prewar.dta", clear
rename parl_year year
ta party_grp mp_manual  if year<1918 & year>1884 /*ERROR*/
di 146/151  /*Labour working-class MPs*/
di 1/151  /*Liberal working-class MPs*/

use "Britain interwar.dta", clear /*ERROR*/
ta party_grp mp_manual if year>=1918
di 325/334 /*Labour working-class MPs*/
